package org.structure.boot.demo.mybatisplus;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @version V1.0.0
 * @Title: GenMybatisPlus
 * @Package org.structure.boot.demo.mybatisplus
 * @Description: 代码生成器
 * @author: chuck
 * @date: 2020/5/29 12:13
 */
public class GenMybatisPlus {

    public static void main(String[] args) {
        //代码生成器
        AutoGenerator autoGenerator = new AutoGenerator();
        //全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        System.out.println("projectPath = " + projectPath);
        globalConfig.setOutputDir(projectPath + "/demo-mybatis-plus/src/main/java");
        globalConfig.setAuthor("chuck");
        globalConfig.setOpen(false);
        autoGenerator.setGlobalConfig(globalConfig);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://192.168.2.243:3306/user?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("mengqi");
        dsc.setPassword("123456");
        autoGenerator.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setModuleName("");
        pc.setParent("org.structure.boot.demo.mybatisplus");
        autoGenerator.setPackageInfo(pc);

        StrategyConfig strategy = new StrategyConfig();
        strategy.setEntityLombokModel(true);
        strategy.setInclude("user");
        //驼峰生成
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        //strategy.setControllerMappingHyphenStyle(true);
        autoGenerator.setStrategy(strategy);
        autoGenerator.execute();

    }

}
